package com.farm.controller.user;

import com.farm.result.Result;
import com.farm.service.GoodsService;
import com.farm.vo.GoodsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @FileName GoodsController
 * @Description
 * @Author Sword
 * @date 2025-02-27
 **/

@RestController("userGoodsController")
@RequestMapping("/user/dish")
@Slf4j
@Api(tags = "用户商品相关接口")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    @Cacheable(cacheNames = "goodsCache",key = "#categoryId")
    public Result<List<GoodsVO>> list(Long categoryId) {
        log.info("根据分类id查询菜品:{}", categoryId);
        List<GoodsVO> goodsVOList = goodsService.getByCategoryId(categoryId);

        return Result.success(goodsVOList);
    }
}
